﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Security.Cryptography;
using System.Text;

namespace Bus_proj.website
{
    public partial class checkLogin : System.Web.UI.Page
    {
        public static string getMd5Hash(string input)
        {
            MD5 md5Hasher = MD5.Create();
            byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
            StringBuilder sBuilder = new StringBuilder();

            for (int i = 0; i < data.Length; i++)
            {
                sBuilder.Append(data[i].ToString("x2"));
            }
            return sBuilder.ToString();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string Connection = ConfigurationManager.ConnectionStrings["Bus_proConnectionString"].ConnectionString;
            string strid = Request.Form["strUser"];
            string strpass = Request.Form["strPass"];
            //Response.Write(strid);
            //Response.Write(strpass);
           // Response.Write("qweryu[]dfghjkxcvb");

            //string str = "hhh<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"";
            //string str2 = "hhh<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"";
            string[] stemp = strid.Split(' ');
            stemp = stemp[0].Split('<');
            string[] stemp2 = strpass.Split(' ');
            stemp2 = stemp2[0].Split('<');
            try
            {
                string check = @"select *
                                from Table_Passenger
                                where Passenger_identification = '" + stemp[0] + "' and password = '" + getMd5Hash(stemp2[0]) + "'";
                SqlCommand sqlcomm = new SqlCommand();
                SqlConnection sqlconn = new SqlConnection(Connection);
                SqlDataAdapter da = new SqlDataAdapter(check, sqlconn);
                DataTable dt = new DataTable();
                da.Fill(dt);
                if (dt.Rows.Count <= 0)
                {
                    Response.Write(0);
                }
                else
                {
                    string id_user = dt.Rows[0]["Passenger_id"].ToString();
                    string name = dt.Rows[0]["Passenger_name"].ToString();
                    Response.Write(1 +" "+ id_user +" "+ name);
                   // Response.Write("true");
                }
            }
            catch (Exception)
            {


            }
//            Response.Write(stemp[1] + "  " + stemp[3]);
        }
    }
}